package com.jackeys.piaems.controller;

import com.jackeys.piaems.annotation.PassJwt;
import com.jackeys.piaems.service.UserService;
import com.jackeys.piaems.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.util.Date;

/**
 * @ClassName: UserController
 * @Description: 用户操作控制器
 * @Author: Jackeys
 * @Date: 2021-06-14 19:34
 * @Version: 1.0
 */
@CrossOrigin
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
    * @Name: login
    * @Description: 处理用户登陆请求
    * @Param: [account, password]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/19 15:30
    * @Version: 1.0
    */
    @PassJwt
    @RequestMapping("/user/login")
    public ResponseVo login(String account,String password){
        return userService.login(account,password);
    }

    /**
    * @Name: register
    * @Description: 处理用户注册请求
    * @Param: [password, email]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/19 15:30
    * @Version: 1.0
    */
    @PassJwt
    @RequestMapping("/user/register")
    public ResponseVo register(String password, String email,String securityCode){
        return userService.register(password,email,securityCode);
    }

    /**
    * @Name: forget
    * @Description: 处理用户找回密码请求
    * @Param: [email, password]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/19 15:31
    * @Version: 1.0
    */
    @PassJwt
    @RequestMapping("/user/forget")
    public ResponseVo forget(String email, String password,String securityCode){
        return userService.forget(email,password,securityCode);
    }

    /**
    * @Name: sendSecurityCode
    * @Description: 处理用户发送验证码请求
    * @Param: [email]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/22 17:01
    * @Version: 1.0
    */
    @PassJwt
    @RequestMapping("/user/sendSecurityCode")
    public ResponseVo sendSecurityCode(String email){
        return userService.sendSecurityCode(email);
    }

    /**
    * @Name: uploadHeadPortrait
    * @Description: 处理用户上传头像的请求
    * @Param: [request, account, file]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/23 20:54
    * @Version: 1.0
    */
    @RequestMapping("/user/uploadHeadPortrait")
    public ResponseVo uploadHeadPortrait(HttpServletRequest request, String account,  MultipartFile file) throws FileNotFoundException {
        return userService.uploadHeadPortrait(request,account,file);
    }
    
    /**
    * @Name: updateUserInf
    * @Description: 处理用户修改个人信息的请求
    * @Param: [account, name, birthday, sex, age, phone, sign, headPortrait]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/23 20:57
    * @Version: 1.0
    */
    @RequestMapping("/user/updateUserInf")
    public ResponseVo updateUserInf(String account, String name, Date birthday, String sex, Integer age, String phone, String sign, String headPortrait){
        return userService.modifyUserInf(account,name,birthday,sex,age,phone,sign,headPortrait);
    }

    /**
    * @Name: getHeadPortrait
    * @Description: 处理登录时系统获取头像的请求
    * @Param: [account]
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/26 5:48
    * @Version: 1.0
    */
    @PassJwt
    @RequestMapping("/user/getHeadPortrait")
    public ResponseVo getHeadPortrait(String account){
        return userService.showHeadPortrait(account);
    }
}
